import sys

from util2 import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QTreeWidgetItem


class Login20250710(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(Login20250710, self).__init__(parent=None)
        self.setupUi(self)

    def setupUi(self, Ui_MainWindow):
        super().setupUi(Ui_MainWindow)
        #子类的扩展
        #设置树形结构中的列数
        self.treeWidget.setColumnCount(2)
        self.treeWidget.setHeaderLabels(['姓名','职务'])
        root=QTreeWidgetItem(self.treeWidget) #创建子节点
        root.setText(0,'组织结构') #设置子节点名称
        #创建字典
        d={'独孤求败':'独孤九剑',
           '一灯大师':'一阳指',
           '郭靖':'降龙十八掌',
           '王重阳':'先天功'}
        #循环字典
        for k,v in d.items():
            #创建子节点
            child = QTreeWidgetItem(root)
            child.setText(0,k)
            child.setText(1,v)
        #设置隔行变色
        self.treeWidget.setAlternatingRowColors(True)
        # 子节点默认展开
        self.treeWidget.expandAll()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    login = Login20250710()
    login.show()
    sys.exit(app.exec_())
